"""
演示Python pymysql库的基础操作
"""
from pymysql import Connection

#构建到MySQL数据库的连接
conn = Connection(
    host="localhost",   #主机名(IP)
    port=3306,        #端口
    user="root",        #账户
    password="123456",   #密码
    # autocommit=True     #自动确认
)

print(conn.get_server_info())
#执行非查询语句性质的SQL
cursor = conn.cursor()
#选择数据库,注意这里是conn.而不是cursor
conn.select_db("test")
cursor.execute("create table student(id int, name varchar(10), age int, gender varchar(3));")
# 执行查询性质的SQL
# cursor.execute("select * from student")
cursor.execute("insert into student values(10001, '周杰伦', 33, '男');")
conn.commit()
#关闭连接
conn.close()